const context = require.context("./lib/components", true, /\.vue$/);
import "viewerjs/dist/viewer.css";
import Viewer from "v-viewer";

const plugin = {
    // 这里要导出一个 install 方法
    install(Vue, options) {
        Vue.use(Viewer, {
            defaultOptions: {
                zIndex: 5000,
            },
        });
        let contextArr = context.keys().filter((v) => context(v).default.name);
        console.log(contextArr, "contextArr");
        if (options && options.components) {
            let components = options.components;
            components.forEach((v) => {
                let contextFilter = contextArr.filter((component) => context(component).default.name === v);
                console.log(contextFilter, "contextFilter");
                contextFilter.forEach((v) => {
                    let component = context(v).default;
                    Vue.component(component.name, component);
                });
            });
        } else {
            contextArr.forEach((v) => {
                let component = context(v).default;
                Vue.component(component.name, component);
            });
        }
    },
};
export default plugin;
